package com.online.studyonline.controller;

import com.online.studyonline.pojo.Result;
import com.online.studyonline.pojo.Watchtime;
import com.online.studyonline.service.WatchtimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/watchtime")
@CrossOrigin
public class WatchtimeController {
    @Autowired
    private WatchtimeService watchtimeService;
    @GetMapping("/getWatchTimeByVideoId")
    public Result getWatchTimeByVideoId(@RequestParam("videoId") Integer videoId, @RequestParam("userId") Integer userId){
//        System.out.println(videoId);
        return Result.success(watchtimeService.lambdaQuery().eq(Watchtime::getVideoId, videoId).eq(Watchtime::getUserId, userId).one());
    }
    @PostMapping("/addWatchTime")
    public Result addWatchTime(@RequestBody Watchtime watchtime){
//        System.out.println(watchtime.getWatchId());
        return Result.success(watchtimeService.save(watchtime));
    }
    @PutMapping("/updateWatchTime")
    public Result updateWatchTime(@RequestBody Watchtime watchtime){
        return Result.success(watchtimeService.updateById(watchtime));
    }
}
